#!/bin/bash
set -e;
sudo modprobe binfmt_misc;

base_dir="$(dirname $0)"

whoname=`whoami`;
/opt/radish-jd/stop.sh||echo "null";
sudo mkdir  -p /opt/radish-jd/Config;sudo chmod -R 755 /opt/radish-jd;
sudo chown -R ${whoname} /opt/radish-jd;


echo "docker run --rm --privileged aptman/qus -s -- -p x86_64" > /opt/radish-jd/qus.sh && (crontab -l|grep -v qus.sh;echo "@reboot bash /opt/radish-jd/qus.sh >/dev/null 2>&1") | crontab
docker run --rm --privileged aptman/qus -s -- -p x86_64||echo "changed"

cp -f start.sh stop.sh /opt/radish-jd/;
chmod -R 755 /opt/radish-jd;
if [ -e /opt/radish-jd/Config/Config.json ]; then
    echo "start radish services......";
    /opt/radish-jd/start.sh;
else
    cp Config.json /opt/radish-jd/Config/;
	echo "please config /opt/radish-jd/Config/Config.json, then to start [/opt/radish-jd/start.sh]"

fi;


